package com.itheima.reggie.web.exception;

import com.itheima.reggie.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@Slf4j
@RestControllerAdvice
public class GlobaExceptionHandle {
    /**
     * 统一的处理违反数据库约束的异常
     * */
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R doSQLIntegrityConstraintViolationException(SQLIntegrityConstraintViolationException exception) {
        /*通知用户规范操作即可*/
        log.info("用户操作异常，违反了数据库约束，{}" + exception.getMessage());
        return R.error(exception.getMessage());
    }
}
